package service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import dao.ProgrammerDao;
import domain.Programmer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ProgrammerService {

    @Autowired
    private ProgrammerDao programmerDao;

    //分页查询程序员
    public PageInfo<Programmer> findAllProgrammer(int pageNum, int pageSize){
        PageHelper.startPage(pageNum,pageSize);
        List<Programmer> all = programmerDao.findAll();
        PageInfo<Programmer> pageInfo = new PageInfo<>(all);
        return pageInfo;
    }

    //新增程序员
    public void addProgrammer(Programmer programmer){
        programmerDao.add(programmer);
    }

    //修改信息
    public void updateProgrammer(Programmer programmer){
        programmerDao.update(programmer);
    }

    //根据id查询信息
    public Programmer findProgrammerById(int id){
       return programmerDao.findById(id);
    }

    //查询可用状态的程序员
    public List<Programmer> findProgrammerByStatus(){
        List<Programmer> byStatus = programmerDao.findByStatus();
        return byStatus;
    }

    //修改状态
    public void updateProgrammerStatus(int[] id,boolean status){
        Programmer programmer = new Programmer();
        programmer.setStatus(status);
        for (int i:id){
            programmer.setId(i);
            programmerDao.updateStatus(programmer);
        }
    }
}
